home *** CD-ROM | disk | FTP | other *** search
/ NeXTSTEP 3.3 (Developer)…68k, x86, SPARC, PA-RISC] / NeXTSTEP 3.3 Dev Intel.iso / NextDeveloper / Headers / architecture / i386 / asm_help.h < prev    next >
Text File  |  1993-06-01  |  5KB  |  237 lines

  1. /* Copyright (c) 1991 NeXT Computer, Inc.  All rights reserved.
  2.  *
  3.  *    File:    architecture/i386/asm_help.h
  4.  *    Author:    Mike DeMoney, NeXT Computer, Inc.
  5.  *    Modified for i386 by: Bruce Martin, NeXT Computer, Inc.
  6.  *
  7.  *    This header file defines macros useful when writing assembly code
  8.  *    for the Intel i386 family processors.
  9.  *
  10.  * HISTORY
  11.  * 10-Mar-92  Bruce Martin (bmartin@next.com)
  12.  *    Adapted to i386
  13.  * 23-Jan-91  Mike DeMoney (mike@next.com)
  14.  *    Created.
  15.  */
  16.  
  17. #ifndef    _ARCH_I386_ASM_HELP_H_
  18. #define    _ARCH_I386_ASM_HELP_H_
  19.  
  20. #import    <architecture/i386/reg_help.h>
  21.  
  22.  
  23. #ifdef    __ASSEMBLER__
  24.  
  25. #define ALIGN                        \
  26.     .align    2, 0x90
  27.  
  28. #define    ROUND_TO_STACK(len)                \
  29.     (((len) + STACK_INCR - 1) / STACK_INCR * STACK_INCR)
  30.  
  31. #ifdef notdef
  32. #define CALL_MCOUNT                        \
  33.     pushl    %ebp                        ;\
  34.     movl    %esp, %ebp                    ;\
  35.     .data                            ;\
  36.     1: .long 0                        ;\
  37.     .text                            ;\
  38.     lea 9b,%edx                        ;\
  39.     call mcount                        ;\
  40.     popl    %ebp                        ;
  41. #else
  42. #define CALL_MCOUNT
  43. #endif
  44.  
  45. /*
  46.  * Prologue for functions that may call other functions.  Saves
  47.  * registers and sets up a C frame.
  48.  */
  49. #define NESTED_FUNCTION_PROLOGUE(localvarsize)            \
  50.     .set    __framesize,ROUND_TO_STACK(localvarsize)    ;\
  51.     .set    __nested_function, 1                ;\
  52.     CALL_MCOUNT                        \
  53.     .if __framesize                        ;\
  54.       pushl    %ebp                        ;\
  55.       movl    %esp, %ebp                    ;\
  56.       subl    $__framesize, %esp                ;\
  57.     .endif                            ;\
  58.     pushl    %edi                        ;\
  59.     pushl    %esi                        ;\
  60.     pushl    %ebx
  61.  
  62. /*
  63.  * Prologue for functions that do not call other functions.  Does not
  64.  * save registers (this is the functions responsibility).  Does set
  65.  * up a C frame.
  66.  */
  67. #define LEAF_FUNCTION_PROLOGUE(localvarsize)            \
  68.     .set    __framesize,ROUND_TO_STACK(localvarsize)    ;\
  69.     .set    __nested_function, 0                ;\
  70.     CALL_MCOUNT                        \
  71.     .if __framesize                        ;\
  72.       pushl    %ebp                        ;\
  73.       movl    %esp, %ebp                    ;\
  74.       subl    $__framesize, %esp                ;\
  75.     .endif
  76.  
  77. /*
  78.  * Prologue for any function.
  79.  *
  80.  * We assume that all Leaf functions will be responsible for saving any
  81.  * local registers they clobber.
  82.  */
  83. #define FUNCTION_EPILOGUE                    \
  84.     .if __nested_function                    ;\
  85.       popl    %ebx                        ;\
  86.       popl    %esi                        ;\
  87.       popl    %edi                        ;\
  88.     .endif                            ;\
  89.     .if __framesize                        ;\
  90.       movl    %ebp, %esp                    ;\
  91.       popl    %ebp                        ;\
  92.     .endif                            ;\
  93.     ret
  94.  
  95.  
  96. /*
  97.  * Macros for declaring procedures
  98.  *
  99.  * Use of these macros allows ctags to have a predictable way
  100.  * to find various types of declarations.  They also simplify
  101.  * inserting appropriate symbol table information.
  102.  *
  103.  * NOTE: these simple stubs will be replaced with more
  104.  * complicated versions once we know what the linker and gdb
  105.  * will require as far as register use masks and frame declarations.
  106.  * These macros may also be ifdef'ed in the future to contain profiling
  107.  * code.
  108.  *
  109.  */
  110.  
  111. /*
  112.  * TEXT -- declare start of text segment
  113.  */
  114. #define    TEXT                        \
  115.     .text
  116.  
  117. /*
  118.  * DATA -- declare start of data segment
  119.  */
  120. #define DATA                        \
  121.     .data
  122.  
  123. /*
  124.  * LEAF -- declare global leaf procedure
  125.  * NOTE: Control SHOULD NOT FLOW into a LEAF!  A LEAF should only
  126.  * be jumped to.  (A leaf may do an align.)  Use a LABEL() if you
  127.  * need control to flow into the label.
  128.  */
  129. #define    LEAF(name, localvarsize)            \
  130.     .globl    name                    ;\
  131.     ALIGN                        ;\
  132. name:                            ;\
  133.     LEAF_FUNCTION_PROLOGUE(localvarsize)
  134.  
  135. /*
  136.  * X_LEAF -- declare alternate global label for leaf
  137.  */
  138. #define    X_LEAF(name, value)                \
  139.     .globl    name                    ;\
  140.     .set    name,value
  141.  
  142. /*
  143.  * P_LEAF -- declare private leaf procedure
  144.  */
  145. #define    P_LEAF(name, localvarsize)            \
  146.     ALIGN                        ;\
  147. name:                            ;\
  148.     LEAF_FUNCTION_PROLOGUE(localvarsize)
  149.  
  150. /*
  151.  * LABEL -- declare a global code label
  152.  * MUST be used (rather than LEAF, NESTED, etc) if control
  153.  * "flows into" the label.
  154.  */
  155. #define    LABEL(name)                    \
  156.     .globl    name                    ;\
  157. name:
  158.  
  159. /*
  160.  * NESTED -- declare procedure that invokes other procedures
  161.  */
  162. #define    NESTED(name, localvarsize)            \
  163.     .globl    name                    ;\
  164.     ALIGN                        ;\
  165. name:                            ;\
  166.     NESTED_FUNCTION_PROLOGUE(localvarsize)
  167.  
  168. /*
  169.  * X_NESTED -- declare alternate global label for nested proc
  170.  */
  171. #define    X_NESTED(name, value)                \
  172.     .globl    name                    ;\
  173.     .set    name,value
  174.  
  175. /*
  176.  * P_NESTED -- declare private nested procedure
  177.  */
  178. #define    P_NESTED(name, localvarsize)            \
  179.     ALIGN                        ;\
  180. name:                            ;\
  181.     NESTED_FUNCTION_PROLOGUE(localvarsize)
  182.  
  183. /*
  184.  * END -- mark end of procedure
  185.  */
  186. #define    END(name)                    \
  187.     FUNCTION_EPILOGUE
  188.  
  189.  
  190. /*
  191.  * Storage definition macros
  192.  * The main purpose of these is to allow an easy handle for ctags
  193.  */
  194.  
  195. /*
  196.  * IMPORT -- import symbol
  197.  */
  198. #define    IMPORT(name)                    \
  199.     .reference    name
  200.  
  201. /*
  202.  * ABS -- declare global absolute symbol
  203.  */
  204. #define    ABS(name, value)                \
  205.     .globl    name                    ;\
  206.     .set    name,value
  207.  
  208. /*
  209.  * P_ABS -- declare private absolute symbol
  210.  */
  211. #define    P_ABS(name, value)                \
  212.     .set    name,value
  213.  
  214. /*
  215.  * EXPORT -- declare global label for data
  216.  */
  217. #define    EXPORT(name)                    \
  218.     .globl    name                    ;\
  219. name:
  220.  
  221. /*
  222.  * BSS -- declare global zero'ed storage
  223.  */
  224. #define    BSS(name,size)                    \
  225.     .comm    name,size
  226.  
  227.  
  228. /*
  229.  * P_BSS -- declare private zero'ed storage
  230.  */
  231. #define    P_BSS(name,size)                \
  232.     .lcomm    name,size
  233.  
  234. #endif    __ASSEMBLER__
  235.  
  236. #endif    _ARCH_I386_ASM_HELP_H_
  237.